<!-- 创建时间: 2019年10月24日 星期四 14:59 用户预约信息中心组件 -->
<template>
    <div class="Respay_container">
        <h5 v-if="parentValue.length==0">
            暂无{{ optionsText }}信息 &nbsp;
            返回<router-link to="/">首页</router-link>
        </h5>
        <div :class="setPanelStyle(item.status)" v-for="(item, index) in parentValue" :key="index">
            <div class="panel-heading">
                <span class="tradeNo">订单号:{{ item.tradeNo }}</span>
                <span>
                    <i class="fa fa-dot-circle-o"></i>
                    {{ showStatusInfo(item.status) }}
                </span>
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <tbody>
                        <tr>
                            <td>车主:{{ item.name }}</td>
                            <td>车牌号:{{ item.licensePlateNumber }}</td>
                        </tr>
                        <tr>
                            <td>预约时间:{{ item.bookingTime }}</td>
                            <td>
                                预约计时:
                                <span
                                    class="label label-warning"
                                >{{ item.status==0 ? Time[index] : item.waitingTime }}</span>
                            </td>
                        </tr>
                        <tr>
                            <td>地址:{{ item.address }}</td>
                            <td>车位:{{ item.bookingParking }}</td>
                        </tr>
                        <tr>
                            <td colspan="2" class="statusShow">
                                <div>{{ showStatusInfo(item.status) }}</div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="panel-footer">
                <div class="row" v-if="item.status!=2 && item.status!=1 && item.status!=3">
                    <div class="col-xs-4">
                        <router-link
                            tag="button"
                            to="/"
                            type="button"
                            class="mui-btn mui-btn-danger mui-btn-block mui-btn-outlined"
                        >
                            <i class="fa fa-home" aria-hidden="true"></i>首页
                        </router-link>
                    </div>
                    <div class="col-xs-4 col-xs-offset-4">
                        <router-link
                            tag="button"
                            to="/"
                            type="button"
                            class="mui-btn mui-btn-danger mui-btn-block mui-btn-outlined"
                        >
                            <i class="fa fa-clock-o" aria-hidden="true"></i>延时入库
                        </router-link>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import error from "../../js/error.js";

export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
        //这里存放数据
        return {
            // 时间倒计时
            Time: [],
            // 定时器
            Interval: "",
            // 秒数
            second: 60
        };
    },
    props: ["parentValue", "optionsText"],
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
        calcBookingTime() {
            this.Time = [];
            console.log(this.parentValue);
            for (var i = 0; i < this.parentValue.length; i++) {
                if (this.parentValue[i].status == 0) {
                    var bookingTime = this.parentValue[i].bookingTime;
                    var waitingTime = this.parentValue[i].waitingTime;
                    var date = new Date(bookingTime);
                    // var setMin = date.getMinutes() + waitingTime;
                    date.setMinutes(date.getMinutes() + waitingTime);
                    console.log('==>',date.toLocaleString());
                    
                    var currentTime = new Date();

                    var minxins = parseInt(
                        (date.getTime() - currentTime.getTime()) / (1000 * 60)
                    );
                    if (minxins <= 0) {
                        this.$http
                            .post("timerEnd", {
                                licensePlateNumber: this.parentValue[i].licensePlateNumber,
                                parking: this.parentValue[i].bookingParking
                            });
                            this.parentValue.splice(i,1);
                            this.$emit("refresh",true);
                        continue;
                    }
                    // minxins = minxins < 10 ? "0" + minxins : minxins;

                    // var second = this.second - currentTime.getSeconds();
                    // second = second < 10 ? "0" + second : second;
                    // console.log("分：", second); + " : " + second

                    this.Time.push(minxins);
                    // if (this.second <= 0) {
                    //     this.second = 60;
                    // }
                } else {
                    break;
                }
            }
            if (this.Time.length == 0) {
                clearInterval(this.Interval);
            }
        },
        setPanelStyle(status) {
            var obj = {
                "panel panel-success": status == 0,
                "panel panel-primary": status == 1,
                "panel panel-info": status == 2,
                "panel panel-danger": status == 3
            };
            return obj;
        },
        showStatusInfo(status) {
            if (status == 0) {
                return "预约成功";
            } else if (status == 1) {
                return "入库成功";
            } else if (status == 2) {
                return "结算成功";
            } else if (status == 3) {
                return "预约超时";
            } else {
                return "暂无信息";
            }
        }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
        this.Interval = setInterval(() => {
            this.calcBookingTime();
        }, 1000);
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {
        
    }
};
</script>

<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../lib/Font-Awesome-master/css/font-awesome.min.css");
.Respay_container {
    // margin-top: 45px;
    h5 {
        text-align: center;
        color: lightslategrey;
    }
    .panel {
        .panel-heading {
            display: flex;
            justify-content: space-between;
            .tradeNo {
                white-space: normal;
                word-break: break-all;
                word-wrap: break-word;
                max-width: 300px;
            }
        }
        .panel-body {
            table {
                margin-bottom: 0px;
                .statusShow {
                    text-align: center;
                    div {
                        border: 2px solid #f0ad4e;
                        padding: 10px;
                        width: 50%;
                        margin: 0 auto;
                        border-radius: 20px;
                        color: #f76969;
                        font-weight: bold;
                    }
                }
            }
        }
        .panel-footer {
            padding: 5px 15px;
            .row {
                button {
                    padding: 6px 0;
                    margin-bottom: 0px;
                }
            }
        }
    }
}
</style>
